﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;

namespace Microsoft.WindowsAzure.Search
{
    public class Analyzer
    {
        public static Dictionary<String, int> ComputeTermFreq(String content)
        {
            // Parse to token
            List<String> tokens = Parser.Parse(content);

            // <term, frequency>
            Dictionary<String, int> termFreq = new Dictionary<String, int>();

            // compute term frequency for each term in a document 
            foreach (String term in tokens)
            {
                // add term to termCount for one document
                if (!termFreq.ContainsKey(term))
                    termFreq.Add(term, 1); // new term
                else
                    termFreq[term]++; // existed term

            }// end of all terms in one document

            return termFreq;
        }

        public static int ComputeLength(Dictionary<String, int> termFreq)
        {
            // compute Length
            int length = 0;
            foreach (int count in termFreq.Values)
            {
                length += count * count;
            }
            return length;
        }
    }
}
